package com.cloudjan.codebuilder.entity;

import lombok.Data;

/**
 * 响应结果类封装
 */
@Data
public class Result{
    private String code;
    private boolean success;
    private String msg;
    private Object data;

    public static Result ok(){
        Result r = new Result();
        r.setCode("200");
        r.setMsg("操作成功");
        r.setSuccess(true);
        return r;
    }

    public static Result ok(String msg){
        Result r = new Result();
        r.setCode("200");
        r.setMsg(msg);
        r.setSuccess(true);
        return r;
    }

    public static Result ok(Object data){
        Result r = new Result();
        r.setData(data);
        r.setCode("200");
        r.setMsg("操作成功");
        return r;
    }

    public static Result ok(String msg,Object data){
        Result r = new Result();
        r.setData(data);
        r.setCode("200");
        r.setMsg(msg);
        return r;
    }

    public static Result fail(){
        Result r = new Result();
        r.setCode("500");
        r.setMsg("操作失败");
        r.setSuccess(false);
        return r;
    }

    public static Result fail(String msg){
        Result r = new Result();
        r.setCode("500");
        r.setMsg(msg);
        r.setSuccess(false);
        return r;
    }

}
